import { defHttp } from '@/utils/http/axios';
import {
  CreateUserReq,
  UserListItem,
  GetUserPageListReq,
  GetUserPageListRes,
  ResetPasswordReq,
  UpdateUserReq,
} from './model/userModel';
import { GetOptionsModel } from '../model/baseModel';

enum Api {
  User = '/system/user',
  UserWithId = '/system/user/{uid}',
  UserResetPassword = '/system/user/{uid}/reset_password',
  UserDisable = '/system/user/{uid}/disable',
  UserEnable = '/system/user/{uid}/enable',
  EditPassword = '/system/user/reset_password',
  UserListOptions = '/system/user/options',
}

//user
export const apiGetUserList = (params: GetUserPageListReq) =>
  defHttp.get<GetUserPageListRes>({ url: Api.User, params });

export const apiCreateUser = (params: CreateUserReq) =>
  defHttp.post({ url: Api.User, params: params });

export const apiUpdateUser = (params: UpdateUserReq) =>
  defHttp.put({ url: Api.User, params: params });

export const apiDeleteUser = (uid: number) =>
  defHttp.delete({ url: Api.UserWithId.replace('{uid}', uid.toString()) });

export const apiUserDetail = (uid: number) =>
  defHttp.get<UserListItem>({ url: Api.UserWithId.replace('{uid}', uid.toString()) });

export const apiResetPwd = (uid: number) =>
  defHttp.put({ url: Api.UserResetPassword.replace('{uid}', uid.toString()) });

export const apiUserDisable = (uid: number) =>
  defHttp.put({ url: Api.UserDisable.replace('{uid}', uid.toString()) });

export const apiUserEnable = (uid: number) =>
  defHttp.put({ url: Api.UserEnable.replace('{uid}', uid.toString()) });

export const apiEditPwd = (params: ResetPasswordReq) =>
  defHttp.put({ url: Api.EditPassword, params });

export const apiGetUserOptions = (params?: GetUserPageListReq) =>
  defHttp.get<GetOptionsModel>({ url: Api.UserListOptions, params });
